package de.wbh.gwt.form.layouter.shared.activity;

import javax.inject.Inject;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.inject.client.AsyncProvider;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.assistedinject.Assisted;

import de.wbh.gwt.form.layouter.shared.Step;

public class LoadStepsActivity extends AbstractActivity {

	private final AsyncProvider<LoadStepsView> viewProvider;
	private final Step step;
	private LoadStepsView view;

	@Inject
	public LoadStepsActivity(AsyncProvider<LoadStepsView> viewProvider, @Assisted Step step) {
		this.viewProvider = viewProvider;
		this.step = step;
	}

	@Override
	public void start(final AcceptsOneWidget panel, EventBus eventBus) {
		this.viewProvider.get(new AsyncCallback<LoadStepsView>() {

			@Override
			public void onFailure(Throwable caught) {
				caught.printStackTrace();
			}

			@Override
			public void onSuccess(LoadStepsView result) {
				LoadStepsActivity.this.view = result;
				LoadStepsActivity.this.view.setStep(LoadStepsActivity.this.step);
				panel.setWidget(LoadStepsActivity.this.view);
			}
		});
	}

}
